
<div style="width: 100%">
    <form id="ff" method="post" style="width:100%;max-width:90%;padding:60px 20px;">
        <div style="margin-bottom:40px">
            <input class="easyui-textbox" name="title" style="width:50%" data-options="label:'标题:',required:true">
        </div>
        <div class="xheditor">
            <input class="easyui-textbox" name="content" style="width:90%;height:160px" data-options="label:'新闻内容:',multiline:true,required:true">
        </div>
        <input type="text" name="_id" style="height:0;border:0;opacity:0;position: absolute;">
    </form>
    <div style="text-align:center;padding:5px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">Clear</a>
    </div>
</div>
<script>
	function submitForm() {
		$('#ff').form('submit', {
			onSubmit: function () {
				var isValid = $(this).form('validate');
				if (isValid) {
					var data = $('#ff').serializeObject();
					if (!(data._id && data._id.trim().length > 0)) {
						//add model
						console.log(data._id);
						delete data._id;
						var nodeData = $('#tree').tree('getSelected');
						data.cateId = nodeData._id;
						$.ajax({
							url: "http://localhost:3000/news/data",
							method: 'post',
							data: data,
							success: function (res) {
								$('#ff').form('clear');
								$('#dd').dialog('close');
								progress();
							}
						})
					} else {
						//edit model
						$.ajax({
							url: "http://localhost:3000/news/data/" + data._id,
							method: 'post',
							data: data,
							success: function (res) {
								$('#ff').form('clear');
								$('#dd').dialog('close');
								progress();
							}
						})
					}
				}
			}
		});
	}
</script>